#include <iostream>
#include <vector>
#include <queue>

const int max_len = 65535;
int main()
{
    int N;
    std::cin >> N;

    int n = 0;

    std::vector<int> du[max_len];
    std::vector<int> v(max_len, 0);
    std::vector<int> lu(max_len, 0);
    for (int i = 0; i < N; i++)
    {
        int id, up_id, sales;
        std::cin >> id >> up_id >> sales;
        du[id].push_back(up_id);
        v[id] += sales;
        lu[up_id]++;
        n = std::max(n, std::max(id, up_id));
    }

    std::queue<int> q;
    for (int i = 0; i <= n; i++)
    {
        if (lu[i] == 0)
        {
            q.push(i);
        }
    }

    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = 0; i < du[u].size(); i++)
        {
            v[du[u][i]] += v[u] / 100 * 15;
            lu[du[u][i]]--;
            if (lu[du[u][i]] == 0)
            {
                q.push(lu[du[u][i]]);
            }
        }

        if (q.size() == 0)
            std::cout << u << " " << v[u] << std::endl;
    }

    return 0;
}